package com.transmit.core;


/**
 * 响应结果生成工具
 */
public class ResultGenerator {
    private static final String DEFAULT_SUCCESS_MESSAGE = "SUCCESS";

    /**
     * 返回成功状态信息（用户增删改返回成功状态信息）
     * @return
     */
    public static Result genSuccessMessage() {
        return new Result()
                .setCode(ResultCode.SUCCESS_CUD)
                .setMessage(DEFAULT_SUCCESS_MESSAGE);
    }


    public static Result genSuccessResult() {
        return new Result()
                .setCode(ResultCode.SUCCESS)
                .setMessage(DEFAULT_SUCCESS_MESSAGE);
    }

    public static Result genSuccessResult(Object data) {
        return new Result()
                .setCode(ResultCode.SUCCESS)
                .setMessage(DEFAULT_SUCCESS_MESSAGE)
                .setData(data);
    }

    public static Result genFailResult(String message) {
        return new Result()
                .setCode(ResultCode.FAIL)
                .setMessage(message);
    }

    /**
     * @param code 错误状态码
     * @param message 错误信息
     * @return
     */
    public static Result genFailResult(int code,String message) {
        return new Result()
                .setCode(code)
                .setMessage(message);
    }
    /**
     * @param errorEnum 错误码枚举对象
     * @return
     */
    public static Result genFailResult(ErrorEnum errorEnum) {
        return new Result()
                .setCode(errorEnum.getErrorCode())
                .setMessage(errorEnum.getErrorMsg());
    }
    /**
     *
     * @param code 错误状态码
     * @param message 错误信息
     * @param data 返回数据对象
     * @return
     */
    public static Result genFailResult(int code,String message,Object data) {
        return new Result()
                .setCode(code)
                .setMessage(message)
                .setData(data);
    }

    /**
     * @param errorEnum 错误码枚举对象
     * @return
     */
    public static Result genFailResult(ErrorEnum errorEnum,Object data) {
        return new Result()
                .setCode(errorEnum.getErrorCode())
                .setMessage(errorEnum.getErrorMsg())
                .setData(data);
    }

}
